package edu.mit.compilers.assembly.x64.codes;

import edu.mit.compilers.assembly.x64.basic.X64Operand;

public class X64BinaryOpCode extends X64Code {

    public enum Type {
        ADD,
        SUB,
        IMUL,
        OR,
        AND,
        XOR,
    }

    // dest = dest op src
    private final X64Operand src;
    private final X64Operand dest;
    private final Type type;

    public X64BinaryOpCode(X64Operand src, X64Operand dest, Type type) {
        this.src = src;
        this.dest = dest;
        this.type = type;
    }

    @Override
    protected String getStringFroShow(String prefix, boolean debug) {
        return prefix + typeToInstruction(type) + TAB + src.getAddress() + "," + TAB + dest.getAddress() + '\n';
    }

    private String typeToInstruction(Type type) {
        switch (type) {
            case ADD:   return "addq";
            case SUB:   return "subq";
            case IMUL:  return "imulq";
            case OR:    return "orq";
            case AND:   return "andq";
            case XOR:   return "xorq";
            default:
                assert false;
                return null;
        }
    }
}
